home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / util / libs / chunky_dev.lha / chunky_dev / Demos / _shared / loadcp.c next >
Encoding:
C/C++ Source or Header  |  1999-03-15  |  1.2 KB  |  79 lines

  1. //
  2. // chunky.library Demo
  3. //
  4. // MODULE: reading of raw chunky data from disk
  5. //
  6. // Public Domain.  (c) 1999 Rosande Limited, all rights reserved.
  7.  
  8. #include <exec/types.h>
  9. #include <dos/dos.h>
  10. #include <pragma/dos_lib.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13.  
  14. #include "loadcp.h"
  15.  
  16. void DEMO_FreeChunky(UBYTE *buf)
  17. {
  18.   if(buf)
  19.   {
  20.     free(buf);
  21.   }
  22. }
  23.  
  24. void DEMO_FreeRGB32(void *buf)
  25. {
  26.   if(buf) free(buf);
  27. }
  28.  
  29. UBYTE *DEMO_LoadChunky(STRPTR FileName, ULONG Width, ULONG Height)
  30. {
  31.   BPTR fh;
  32.   ULONG size;
  33.   UBYTE *buf = NULL; int ok = FALSE;
  34.  
  35.   if(fh = Open(FileName, MODE_OLDFILE))
  36.   {
  37.     size = Width * Height;
  38.     if(buf = (UBYTE *)malloc(size))
  39.     {
  40.       if(Read(fh, buf, size) == size)
  41.       {
  42.         // Done
  43.         ok = TRUE;
  44.       }
  45.     }
  46.     Close(fh);
  47.   }
  48.   if(!ok)
  49.   {
  50.     DEMO_FreeChunky(buf); buf = NULL;
  51.   }
  52.   return(buf);
  53. }
  54.  
  55. void *DEMO_LoadRGB32(STRPTR FileName)
  56. {
  57.   BPTR fh;
  58.   ULONG size = 3080;
  59.   void *buf = NULL; int ok = FALSE;
  60.  
  61.   if(fh =  Open(FileName, MODE_OLDFILE))
  62.   {
  63.     if(buf = malloc(size))
  64.     {
  65.       if(Read(fh, buf, size) == size)
  66.       {
  67.         ok = TRUE;
  68.       }
  69.     }
  70.     Close(fh);
  71.   }
  72.   if(!ok)
  73.   {
  74.     DEMO_FreeRGB32(buf);
  75.     buf = NULL;
  76.   }
  77.   return(buf);
  78. }
  79.